﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_surface_area
{
    public DAL_tbl_surface_area()
    {

    }



    public List<tbl_surface_area> select(int SURFACE_AREA_ID)
    {
        List<tbl_surface_area> list = new List<tbl_surface_area>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select SURFACE_AREA_ID,SURFACE_AREA_TYPE,IS_ACTIVE,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE from tbl_surface_area where SURFACE_AREA_ID=@SURFACE_AREA_ID";
        cmd.Parameters.AddWithValue("@SURFACE_AREA_ID", SURFACE_AREA_ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_surface_area()
            {
                SURFACE_AREA_ID = Convert.ToInt32(dr["SURFACE_AREA_ID"]),
                SURFACE_AREA_TYPE = dr["SURFACE_AREA_TYPE"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                MODIFIED_BY = dr["MODIFIED_BY"].ToString(),
                MODIFIED_DATE = dr["MODIFIED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_surface_area> selectAll()
    {
        List<tbl_surface_area> list = new List<tbl_surface_area>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select SURFACE_AREA_ID,SURFACE_AREA_TYPE,IS_ACTIVE,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE from tbl_surface_area Order By SURFACE_AREA_ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_surface_area()
            {
                SURFACE_AREA_ID = Convert.ToInt32(dr["SURFACE_AREA_ID"]),
                SURFACE_AREA_TYPE = dr["SURFACE_AREA_TYPE"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                MODIFIED_BY = dr["MODIFIED_BY"].ToString(),
                MODIFIED_DATE = dr["MODIFIED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String SURFACE_AREA_TYPE, bool IS_ACTIVE, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_surface_area(SURFACE_AREA_TYPE, IS_ACTIVE, CREATED_BY, CREATED_DATE)
                        values(@SURFACE_AREA_TYPE, @IS_ACTIVE, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SURFACE_AREA_TYPE", SURFACE_AREA_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int SURFACE_AREA_ID, String SURFACE_AREA_TYPE, bool IS_ACTIVE, String MODIFIED_BY, DateTime MODIFIED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_surface_area SET SURFACE_AREA_TYPE=@SURFACE_AREA_TYPE, IS_ACTIVE=@IS_ACTIVE, MODIFIED_BY=@MODIFIED_BY, MODIFIED_DATE=@MODIFIED_DATE WHERE SURFACE_AREA_ID=@SURFACE_AREA_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SURFACE_AREA_ID", SURFACE_AREA_ID);
        cmd.Parameters.AddWithValue("@SURFACE_AREA_TYPE", SURFACE_AREA_TYPE);
        cmd.Parameters.AddWithValue("@IS_ACTIVE", IS_ACTIVE);
        cmd.Parameters.AddWithValue("@MODIFIED_BY", MODIFIED_BY);
        cmd.Parameters.AddWithValue("@MODIFIED_DATE", MODIFIED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int SURFACE_AREA_ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_surface_area WHERE SURFACE_AREA_ID=@SURFACE_AREA_ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@SURFACE_AREA_ID", SURFACE_AREA_ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}